# -*- coding: utf-8 -*-

import glob, os
import time


def get_tmp_size():
    path = '/tmp/'
    dmrg_tmp_files = glob.glob(path+'*ALPS*')
    totalsize = 0
    for filename in dmrg_tmp_files:
        filesize = os.path.getsize(filename)
        totalsize += filesize
    totalsize = totalsize / (2**30)  ##size in GiB
    return totalsize


max_tmp_size = 0
while True:
    tmp_size = get_tmp_size()
    if tmp_size > max_tmp_size:
        max_tmp_size = tmp_size
    print('DMRG temp files in /tmp have size %.1f GiB, max GiB history %.1f' %
          (tmp_size, max_tmp_size))
    time.sleep(0.5)
